/*
 * @Date: 2024-03-25 15:58:26
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2025-01-08 16:26:39
 * @Description: 判断环境的通用定义
 */
import { computed, unref } from 'vue'
import { useRoute } from 'vue-router'
import { useUserStore } from '@/stores/modules';
// 环境变量
const envMode = import.meta.env.MODE
/**
 * 环境变量定义
 * 
 * @returns 
 */
export const useEnv = () => {

  // 是否生产环境
  const isProdEnv = computed(() => {
    return import.meta.env.PROD
  })

  // 是否安徽环境
  const isAnhuiEnv = computed(() => {
    return envMode === 'ad34'
  })

  // 是否福建环境
  const isFujianEnv = computed(() => {
    return envMode === 'ad35'
  })

  // 是否四川环境
  const isSiChuanEnv = computed(() => {
    return envMode === 'ad51'
  })

  return {
    envMode: envMode,
    isProdEnv: unref(isProdEnv),
    isAnhuiEnv: unref(isAnhuiEnv),
    isFujianEnv: unref(isFujianEnv),
    isSiChuanEnv: unref(isSiChuanEnv),
    fileBusiType: import.meta.env.VITE_FILE_BUSI_TYPE,
  }
}

/**
 * 业务环境状态
 *
 * @returns 
 */
export const useBusiEnv = () => {

  // 用户信息
  const userInfo = useUserStore().userInfo


  // 安徽环境
  const { isAnhuiEnv } = useEnv()


  // 是否为主管部门(只判断url是否存在isDept)
  const isDept = computed(() => {
    let isDept = false
    // 路由查询参数
    const routeQuery = useRoute().query
    if (routeQuery.hasOwnProperty('isDept')) {
      isDept = true
    } else {
      isDept = false
    }

    return isDept
  })
  // 是否为主管部门
  const isDeptEnv = computed(() => {
    let isDept = false
    // 路由查询参数
    const routeQuery = useRoute().query
    if (routeQuery.hasOwnProperty('isDept')) {
      // 安徽环境
      if (isAnhuiEnv) {
        // userType: 1-财政 2-部门
        isDept = (userInfo?.userType == 1) ? false : true
      } else {
        isDept = true
      }
    } else {
      isDept = false
    }

    return isDept
  })

  return {
    isDeptEnv: isDeptEnv.value,
    isDept: isDept.value
  }
}
